/*** 
 * @Author: Wrz
 * @version: g++ -std=c++17
 * @Date: 2021-10-12 15:19:24
 * @LastEditors: Wrz
 * @LastEditTime: 2021-10-14 13:41:54
 */
#include "Constants.h"
#include "data.h"
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

Data_Generator::Data_Generator() {}
Data_Generator::~Data_Generator() {}

void Data_Generator::setWorkspace(const string &s)
{
    this->workspace = s;
}

string Data_Generator::getWorkspace() const
{
    return this->workspace;
}

void Data_Generator::make_input(const string &prefix, int data_id, const string &ext, auto input, const string &info)
{
    cerr << info;
    this->in = this->workspace + prefix + to_string(static_cast<int>(data_id)) + "." + ext;
    cerr << this->in << endl;
    ofstream __File;
    __File.open(this->in.c_str());
    __File.close();

    freopen(this->in.c_str(), "w", stdout);
    input();
}

void Data_Generator::make_bad_input(const string &prefix, int data_id, const string &ext, auto input, const string &info)
{
    cerr << info;
    this->in = this->workspace + prefix + to_string(static_cast<int>(data_id)) + "." + ext;
    cerr << this->in << endl;
    ofstream __File;
    __File.open(this->in.c_str());
    __File.close();

    freopen(this->in.c_str(), "w", stdout);
    input();
}

Solver::Solver() {}

Solver::~Solver() {}

void Solver::setWorkspace(const string &s)
{
    this->workspace = s;
}

string Solver::getWorkspace() const
{
    return this->workspace;
}

void Solver::solveOne() const
{

}

void Solver::make_output(const string &prefix, int data_id, const string &ext, auto solution, const string &info)
{   
    cerr << info;
    this->in = this->workspace + prefix + to_string(static_cast<int>(data_id)) + ".in";
    this->out = this->workspace + prefix + to_string(static_cast<int>(data_id)) + "." + ext;
    cerr << this->out << endl;
    ofstream __File;
    __File.open(this->out.c_str());
    __File.close();

    freopen(this->in.c_str(), "r", stdin);
    freopen(this->out.c_str(), "w", stdout);
    solution();
}

void setWorkspace(const string &s)
{
    data_generator.setWorkspace(s);
    solver.setWorkspace(s);
}
